package cn.wn.service.impl;

import cn.wn.mapper.UserMapper;
import cn.wn.pojo.User;
import cn.wn.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    // 注入mapper
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public void save(User user) {
        userMapper.add(user);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void delete(Integer id) {
        userMapper.delete(id);
    }

    @Override
    public User findByName(String name) {
        return userMapper.findByName(name);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize) {
        // 在需要查询分页的方法前开启分页的支持
        PageHelper.startPage(pageNum,pageSize);
        // 查询，会自动分页
        List<User> list = userMapper.findAll();
        return new PageInfo(list);
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }
}
